package com.laughing.httpserver.handler;

import javax.servlet.ServletOutputStream;
import javax.servlet.WriteListener;
import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;

/**
 * @author laughing.sheng <laughing1917@yeah.net/>
 * @date 2018/1/26
 * socket.getOutputStream的包装类
 */
public class HttpSocketOutputStream extends ServletOutputStream {

    private Socket socket;
    
    private OutputStream outputStream;

    public HttpSocketOutputStream(Socket socket) {
        this.socket = socket;
        try {
            this.outputStream=socket.getOutputStream();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    @Override
    public boolean isReady() {
        return false;
    }

    @Override
    public void setWriteListener(WriteListener writeListener) {

    }

    @Override
    public void write(int b) throws IOException {
        outputStream.write(b);
    }

    @Override
    public void print(String s) throws IOException {
        super.print(s);
    }

    @Override
    public void print(boolean b) throws IOException {
        super.print(b);
    }

    @Override
    public void print(char c) throws IOException {
        super.print(c);
    }

    @Override
    public void print(int i) throws IOException {
        super.print(i);
    }

    @Override
    public void print(long l) throws IOException {
        super.print(l);
    }

    @Override
    public void print(float f) throws IOException {
        super.print(f);
    }

    @Override
    public void print(double d) throws IOException {
        super.print(d);
    }

    @Override
    public void println() throws IOException {
        super.println();
    }

    @Override
    public void println(String s) throws IOException {
        super.println(s);
    }

    @Override
    public void println(boolean b) throws IOException {
        super.println(b);
    }

    @Override
    public void println(char c) throws IOException {
        super.println(c);
    }

    @Override
    public void println(int i) throws IOException {
        super.println(i);
    }

    @Override
    public void println(long l) throws IOException {
        super.println(l);
    }

    @Override
    public void println(float f) throws IOException {
        super.println(f);
    }

    @Override
    public void println(double d) throws IOException {
        super.println(d);
    }

    @Override
    public void write(byte[] b) throws IOException {
        outputStream.write(b);
    }

    @Override
    public void write(byte[] b, int off, int len) throws IOException {
        outputStream.write(b, off, len);
    }

    @Override
    public void flush() throws IOException {
        outputStream.flush();
    }

    @Override
    public void close() throws IOException {
        outputStream.close();
    }
}
